import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class List {
    public static void main(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hu");
        System.out.println(list1);
        ArrayList<String> list2 = new ArrayList<>(10);
    }
    public static void main4(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("bit");
        list1.add("hahaha");
        list1.add("b");
        list1.add("h");
        /*List<String> sub = list1.subList(1,3);
        System.out.println(sub);
        System.out.println(list1);*/
        //System.out.println(list1.contains("bit"));
//        System.out.println(list1.indexOf("bit"));
//        System.out.println(list1.lastIndexOf("bit"));
        //String ret = list1.remove(0);
//        boolean ret = list1.remove("bit");
        //String ret = list1.get(0);
        //String ret = list1.set(0,"hu");
//        list1.clear();
//        System.out.println(list1);
       /* list1.add(0,"hu");
        System.out.println(list1);

        ArrayList<String> list2 = new ArrayList<>();
        list2.add("h");
        list2.add("b");
        list2.add("ha");
        list1.addAll(list2);
        System.out.println(list1);*/
    }
    public static void main3(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("bit");
        list1.add("hahaha");
        //迭代器list打印
        ListIterator<String> it1 = list1.listIterator();
        while (it1.hasNext()){
            String ret = it1.next();
            if (ret.equals("hello")){
                it1.add("hu");
            }else {
                System.out.println(ret + " ");
            }
            System.out.println(list1);

        }
    }
    public static void main2(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("bit");
        list1.add("hahaha");
        //迭代器打印
        /*Iterator<String> it = list1.iterator();
        while (it.hasNext()){
            String ret = it.next();
            if (ret.equals("hello")){
                it.remove();
            }else {
                System.out.println(ret + " ");
            }
            //System.out.println(it.next()+" ");
        }
        System.out.println();*/
        //迭代器list打印
        ListIterator<String> it1 = list1.listIterator();
        while (it1.hasNext()){
            String ret = it1.next();
            if (ret.equals("hello")){
                it1.remove();
            }else {
                System.out.println(ret + " ");
            }
            //System.out.println(it1.next()+" ");

        }
    }
    public static void main1(String[] args) {
//        List<String> list = new ArrayList<>(10);
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("bit");
        list1.add("hahaha");
        System.out.println(list1);
        for (int i = 0; i <list1.size(); i++){
            System.out.print(list1.get(i)+" ");
        }
        for (String s:list1) {
            System.out.println(s+" ");
        }
        //迭代器打印
        Iterator<String> it = list1.iterator();
        while (it.hasNext()){
            System.out.println(it.next()+" ");
        }
        System.out.println();
        //迭代器list打印
        ListIterator<String> it1 = list1.listIterator();
        while (it1.hasNext()){
            System.out.println(it1.next()+" ");

        }

    }
}
